﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.Statistical;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem
{
    public partial class DeleteRow : System.Web.UI.Page
    {
        public string TableName { get; set; }
        public string Year { get; set; }
        public string Month { get; set; }
        public string DWBM { get; set; }
        public string ZBBM { get; set; }
        public string CJ { get; set; }
        public string ROWID { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            ROWID = Request.Form["rowid"].ToRequestString();
            TableName = Request.Form["tn"].ToRequestString();
            ZBBM = Request.Form["zbbm"].ToRequestString();
            DWBM = Request.Form["dwbm"].ToRequestString();
            Month = Request.Form["month"].ToRequestString();
            Year = Request.Form["year"].ToRequestString();
            Response.Clear();
            bool q = Maticsoft.DBUtility.DbHelperOra.Exists("select count(1) from enco_zbbmb where ZBBM='"+ZBBM+"'");
            if (!q)
            {
                GridData gd = new GridData();
                UpdateHC(ZBBM);
                gd.DeleteRow(TableName, ROWID);                
                
            }
            else
            {
                Response.Write("这是指标编码表中的一个节点，不能删除");
            }
            Response.End();
        }

        protected void UpdateHC(string selectZBBM)
        {

            string sql = "select HC from " + TableName + " where NF='" + Year + "' and YF='" + Month + "' and DWBM='" + DWBM + "' and ZBBM = '" + selectZBBM + "'";
            int HC = Maticsoft.DBUtility.DbHelperOra.GetSingle(sql).ToInt32(); 
            
            sql = "update "+TableName+" set HC=HC-1 where HC>"+HC;
            Maticsoft.DBUtility.DbHelperOra.ExecuteSql(sql);
        }
    }
}